package model;

import java.sql.ResultSet;

public class Usuarios extends BasicBean {

    public String cedula = "";
    public String nombre = "";
    public String clave = "";
    public String telefono = "";
    public String correo = "";
    public String nitEmpresa = "";

    public Usuarios() {
    }

    public Usuarios(ResultSet rs) {
        try {

            cedula = validateString(rs.getString("cedula"));
            nombre = validateString(rs.getString("nombre"));
            clave = validateString(rs.getString("clave"));
            telefono = validateString(rs.getString("telefono"));
            correo = validateString(rs.getString("correo"));
            nitEmpresa = validateString(rs.getString("nitEmpresa"));
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    @Override
    public String getUpdateSql() {
        String sql = "";



        sql = "insert into Usuarios( nombre, clave, telefono, cedula, correo, nitEmpresa ) values( '"
                + nombre + "', md5('"
                + clave + "'), '"
                + telefono + "', '"
                + cedula + "', '"
                + correo + "', '"
                + nitEmpresa + "' )";



        return sql;
    }

    public String getUpdateSql2(){
        String sql;
        if (this.clave.isEmpty()) {
        sql = "update Usuarios set nombre = '" +
        nombre + "',  telefono= '" +
        telefono + "', correo= '" +
        correo + "', nitEmpresa= '" +
        nitEmpresa + "' where cedula = '" + cedula + "';";

        } else {

        sql = "update Usuarios set nombre = '" +
        nombre + "', clave= md5('" +
        clave + "'), telefono= '" +
        telefono + "', correo= '" +
        correo + "', nitEmpresa= '" +
        nitEmpresa + "' where cedula = '" + cedula + "';";
        }
        return sql;
    }

    @Override
    public String getHtmlRow() {
        String sz = "";
        sz += "<td class='st4middle'>" + cedula + "</td>";
        sz += "<td class='st4middle'>" + nombre + "</td>";
        sz += "<td class='st4middle'>" + telefono + "</td>";
        sz += "<td class='st4middle'>" + correo + "</td>";
        return sz;
    }

    @Override
    public String getCSVRow() {
        String sz = "";
        sz += "\"" + cedula + "\", ";
        sz += "\"" + nombre + "\", ";
        sz += "\"" + clave + "\", ";
        sz += "\"" + telefono + "\", ";
        sz += "\"" + correo + "\", \r\n";
        return sz;
    }
    @Override
    public String getIdentifier() {
        return "idUsuarios=" + id;
    }
}
